package cn.hcbycloud.auth.hystrix;


import cn.hcbycloud.auth.client.ExternalPermissionCheckClient;
import cn.hcbycloud.auth.dto.LoginInfoDTO;
import cn.hutool.core.collection.CollUtil;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author gaoh
 * @desc OpenFeign 集成 Hystrix
 * @date 2022年02月09日 下午 2:28
 */
@Slf4j
@Component
public class ExternalPermissionCheckClientFallback implements FallbackFactory<ExternalPermissionCheckClient> {

    @Override
    public ExternalPermissionCheckClient create(Throwable throwable) {
        log.warn("ExternalPermissionCheckClient error " + "(Hystrix FallbackFactory): [{}]", throwable.getMessage(), throwable);
        return new ExternalPermissionCheckClient() {
            @Override
            public List<String> getPermissionsByFeign(LoginInfoDTO loginInfoDTO) {
                return CollUtil.newArrayList();
            }
            @Override
            public List<String> getRolesByFeign(LoginInfoDTO loginInfoDTO) {
                return CollUtil.newArrayList();
            }
        };
    }
}
